﻿package  {
	import flash.display.*;
	import flash.events.*;
	public class Zutat extends Sprite {
		var topf:Topf;
		var toepfe:Array;
		var zname:String;
		var s:Zisch;
		var siedepunkt:int;
		var temp:int;
		public function Zutat() {
			addEventListener(Event.ENTER_FRAME, pruefeTemp);
			addEventListener(MouseEvent.MOUSE_UP, pruefeOrt);
			addEventListener(MouseEvent.MOUSE_DOWN, verschieben);
		}
		
		public function setzeToepfe(toepfe:Array):void {
			this.toepfe = toepfe;
		}
		

		private function verschieben(event:MouseEvent):void {
			this.startDrag();
		}
		
		private function pruefeOrt(event:MouseEvent):void {
			this.stopDrag();

			for (var i=0; i< toepfe.length; i++){
				if (hitTestObject(toepfe[i])){
					topf = toepfe[i];
					break;
				}
				else {
					topf = null;
					temp = 0;
				}
			}
		}
		
		private function pruefeTemp(e:Event):void{
			if (topf!=null){
				if (temp > siedepunkt && s == null) {
					s = new Zisch("sound");
				}
				if (temp < siedepunkt && s != null) {
					s.stopSound();
					s = null;
				}
			}
			else if (topf == null && s != null) {
				s.stopSound();
				s = null;
			}
		}
	}
}
